import 'dart:io';

import 'package:dio/dio.dart';
import 'package:flutter_roujiaosuo/constants/common_constants.dart';
import 'package:flutter_roujiaosuo/flutter_bloc/requests/dio_util.dart';
import 'package:flutter_roujiaosuo/flutter_bloc/requests/request/index.dart';
import 'package:flutter_roujiaosuo/models/weather_model.dart';

class WeatherApi {
  Future<int> getLocationInfo(String location) async {
    final url = RoujiaosuoApi.Weather_Location + '?query=$location';
    BaseOptions options = BaseOptions();
    options.connectTimeout = 1000 * 8;
    options.receiveTimeout = 1000 * 10;
    options.contentType =
        ContentType.parse("application/x-www-form-urlencoded");
    Map map = {"query": location};
    Dio dio = new Dio();
    Response response = await dio.get("https://www.baidu.com/");
    print(response.data);
    try {
      Response res = await dio.get(
          'https://www.metaweather.com/api/location/search/?query=beijing');
      print(res);
      int a = res.data;
      return a;
    } catch (e) {
      print(e);
      int a = 0;
      return a;
    }
    // Response res = await DioUtil().requestWithNoProcess(Method.get, url,
    //     option: options, queryParameters: map);
    // print(res);
  }

  Future<Weather> getWeatherData(int locationId) async {
    Options options = Options();
    options.method = Method.get;
    options.connectTimeout = 1000 * 5;
    options.receiveTimeout = 1000 * 8;
    BaseResp<Weather> res = await DioUtil().request<Weather>(
        Method.get,
        RoujiaosuoApi.Weather_Data + locationId.toString(),
        BaseProcessor(false, fun: Weather.generObj),
        option: options);
    print(res);
    return res.data;
  }
}
